package 数组;

public class 快速排序 {
    public static void quickSort(int[] arr, int start, int end) {
        if(start < end){
            int i = start, j = end;
            while(i < j){
                while (i < j && arr[i] <= arr[j]) j--;//以数组的第一个值为轴值，扫描右半页
                if(i < j){
                    int t = arr[i];
                    arr[i] = arr[j];
                    arr[j] = t;
                    i++;
                }
                while (i < j && arr[i] <= arr[j]) i++;//扫描左半页
                if(i < j){
                    int t = arr[i];
                    arr[i] = arr[j];
                    arr[j] = t;
                    j--;
                }
            }
            quickSort(arr, start, i - 1);
            quickSort(arr, i + 1, end);
        }
    }
    public static void main(String[] args) {
        int[] arr = new int[]{12,34,11,78,232,-12,-453,4};
        for (int i:arr) {
            System.out.print(i + " ");
        }
        System.out.println();
        quickSort(arr, 0, arr.length-1);
        for (int i:arr) {
            System.out.print(i + " ");
        }
    }


}
